<? 
    session_start();
	require_once ("core/conn.php");
	$db = get_conn();
	check_session();
	
	$id = $_GET['id'];
	if($id != ''){
		$sql = " select * from modulos where id_modulo='".$id."'"; 
		$result = mysql_query($sql);	
		if($result){
			$row = mysql_fetch_array($result);
			 $id_modulo = $row['id_modulo'];
			 $name = $row['name'];
			 $link = $row['link'];
			 $categoria_id = $row['categoria_id'];
			 $target = $row['target'];
			 $nivel = $row['nivel'];
			 $top = $row['top'];
			 $foother = $row['foother'];
			 $description = $row['description'];
			 $file = $row['file'];			 
			 
		}else{
			
			error_handling(__FUNCTION__.$sql,mysql_error());
		}
	}
	//get_header();
?>
<html>
<head>
<link href="css/admin_styles.css" rel="stylesheet" type="text/css" />
<script>
function check_modules(obj){
							
			
						
							
		if(obj.name.value ==''){
								
			alert('Please fill the name');
								
			obj.name.focus();
								
			return false;
							
		}
							
		if(obj.link.value ==''){
								
			alert('Please fill the link');
								
			obj.link.focus();
								
			return false;
							
		}
							

							
		if(obj.file.value ==''){
								
			alert('Please fill the file');
								
			obj.file.focus();
								
			return false;
							
		}
	return true;
						
	}
</script>

</head>
<body>
<table width="100%" border="0">
              <tr>
                <td><a href="modulos_form.php">Crear Nuevo Modulo</a></td>
              </tr>
              <tr>
                <td><? $sql = "select id_modulo as id, m.name as description,link,m.nivel,cm.name 
					from modulos m, menu_categories cm
					where m.id_category = cm.id_category
					order by cm.id_category,m.nivel,m.name";
					
					
			$result = mysql_query($sql);
			if($result){
			
			    $counter=0;   
				$data ="<table width='100%'>";
				if(mysql_num_rows($result) > 0){
					while($row = mysql_fetch_array($result)){
					$counter ++;
					 if($counter % 2 ==0){
							$class_ = "sub";
								}else{
									$class_ = "sub2";
								}  
					
						if($cat != $row['name']){
							$data .= 
							"<tr>
								<td align='left' colspan='3' bgcolor='#CCCCCC'>
									".$row['name']."
								</td>		
													
							</tr>";
							$cat = $row['name'];
						}
						$data .= 
						"<tr class='".$class_."'>
							<td align='left'>
								".$row['nivel']."
							</td>							
							<td align='left'>
								<a class='ac_vinculo1' href='modulos_form.php?id=".$row['id']."'>  ".$row['description']."</a>
							</td>
							<td align='left'>
								<a class='ac_vinculo1' href='".$row['link']."' target='_blank'>".$row['link']."</a>
							</td>
						
								
						</tr>";
					}//while
				}//if
				else{
					$data .= "<tr><td align='center'>No hay modulos registrados</td></tr>";			
				}
				$data .="</table>";
			}else{
				
				error_handling(__FUNCTION__.$sql,mysql_error());
			}
			echo $data;
			?> </td>
              </tr>
</table>
</body></html>
